#pragma once
#include "Buffer.h"
#include "Channel.h"
namespace xncc {
namespace foundation {
    /// TCP通信的channel  封装了一个fd
    /// TCP chanel  把收到的完整消息放到 全局的消息队列中去 不需要关注消息的回调
    /// TCP         channel 的写消息， 不需要通过 全局队列实现， 不需要关注消息的回调
    class StreamSocketChannel final : public Channel
    {
      public:
        using WriteCompleteCallback = std::function<void(const StreamSocketChannel*)>;
        StreamSocketChannel(EventLoop* loop, int sock_fd, types::connection_id_t connId);
        ~StreamSocketChannel() override;

        StreamSocketChannel(const StreamSocketChannel&)             = delete;
        StreamSocketChannel(const StreamSocketChannel&&)            = delete;
        StreamSocketChannel& operator=(const StreamSocketChannel&)  = delete;
        StreamSocketChannel& operator=(const StreamSocketChannel&&) = delete;

        auto Type() -> ChannelType::value override { return ChannelType::TCP_CHANNEL; }
        void handleRead() override;
        // void handleClose() override;
        void handleWrite() override;

        void sendMsg(const char* msg, size_t len);

      private:  // 列表初始化
        const uint32_t HEADER_LEN;

        Buffer                inputBuffer_;
        Buffer                outputBuffer_;
        WriteCompleteCallback writeCompleteCallback_;
    };
}  // namespace foundation
}  // namespace xncc